import os
from typing import Dict, Any


class Settings:
    """应用配置"""

    # 数据库配置
    # DATABASE_URL = os.getenv("DATABASE_URL", "mysql+pymysql://root:root@127.0.0.1/layer-video?charset=utf8")
    # DATABASE_URL = os.getenv("DATABASE_URL", "mysql+pymysql://layer-video:AzkmhAMTxWZfkAAX@127.0.0.1:3336/layer-video?charset=utf8")
    DATABASE_URL = os.getenv("DATABASE_URL", "mysql+pymysql://layer-video:AzkmhAMTxWZfkAAX@154.82.84.82:3336/layer-video?charset=utf8")

    # SQL日志配置
    SQL_DEBUG = os.getenv("SQL_DEBUG", "false").lower() == "true"
    SQL_DEBUG_DETAIL = os.getenv("SQL_DEBUG_DETAIL", "false").lower() == "true"
    SQL_LOG_FILE = os.getenv("SQL_LOG_FILE", "")  # 空字符串表示不输出到文件

    # 全局序列化配置
    SERIALIZATION_CONFIG = {
        "datetime_format": "%Y-%m-%d %H:%M:%S",
        "exclude_fields": {"password", "api_key", "secret"}
    }

    # 批量处理配置
    BATCH_SIZE = 500

    def get_db_session_config(self, **kwargs) -> Dict[str, Any]:
        """获取数据库会话配置"""
        config = {
            "serialize_results": True,
            "datetime_format": self.SERIALIZATION_CONFIG["datetime_format"],
            "exclude_fields": self.SERIALIZATION_CONFIG["exclude_fields"],
            "batch_size": self.BATCH_SIZE
        }
        config.update(kwargs)
        return config

    def get_sql_log_config(self) -> Dict[str, Any]:
        """获取SQL日志配置"""
        return {
            "enabled": self.SQL_DEBUG,
            "detail": self.SQL_DEBUG_DETAIL,
            "log_file": self.SQL_LOG_FILE if self.SQL_LOG_FILE else None
        }


# 创建全局配置实例
settings = Settings()